package com.zw.design.pattern.creational.singleton.threadlocal;

/***
 * 空间换时间的单例模式
 * 在这个线程当中 获取到这个对象是唯一的
 */
public class ThreadLocalInstance {
    private  static final ThreadLocal<ThreadLocalInstance> threadLocalInstance=new InheritableThreadLocal<ThreadLocalInstance>(){
        @Override
        protected ThreadLocalInstance initialValue() {
            return new ThreadLocalInstance();
        }
    };

    private ThreadLocalInstance(){

    }

    public static ThreadLocalInstance getThreadLocalInstance() {
        return threadLocalInstance.get();
    }
}
